import requset from '../utils/requset'
import { getToken } from '@/utils/token'
export * from '@/api/Atricle'
/**
 * 登陆
 * @param {*} mobile,
 * @param {*} code ,
 * @returns  Promise对象
 */

export const LoginAPI = ({ mobile, code }) => requset({
  url: '/v1_0/authorizations',
  method: 'POST',
  data: {
    mobile,
    code
  }
})
// 刷新用户token
export const updateLoginAPI = () => requset({
  url: '/v1_0/authorizations',
  method: 'PUT',
  headers: {
    Authorization: 'Bearer ' + localStorage.getItem('refresh_token')
  }
})
// 获取所有频道
export const getChannelListAPI = () => requset({
  url: '/v1_0/channels',
  method: 'GET'
})
// 获取用户频道
export const getlistAPI = () => requset({
  url: '/v1_0/user/channels',
  headers: {
    Authorization: `Bearer ${getToken()}`
  }
})

// 设置用户频道
export const changechannelsAPI = (channels) => requset({
  url: '/v1_0/user/channels',
  method: 'PUT',
  headers: {
    Authorization: `Bearer ${getToken()}`
  },
  data: {
    channels
  }
})
// 删除指定用户频道
export const removechannelsAPI = (target) => requset({
  url: `/v1_0/user/channels/${target}`,
  method: 'DELETE',
  headers: {
    Authorization: `Bearer ${getToken()}`,
    'content-type': 'application/x-www-form-urlencoded'
  }
})

export const articleAPI = ({ channel_id, timestamp = new Date() }) => requset({
  url: '/v1_0/articles',
  method: 'GET',
  headers: {
    Authorization: `Bearer ${getToken()}`
  },
  params: {
    channel_id,
    timestamp
  }
})

// 不喜欢文章
export const dislikeArticleAPI = (artId) => requset({
  url: '/v1_0/article/dislikes',
  method: 'POST',
  headers: {
    Authorization: `Bearer ${getToken()}`
  },
  data: {
    target: artId
  }
})
// 举报文章
export const reportsArticleAPI = (artId, type, remark = '没有问题') => requset({
  url: '/v1_0/article/reports',
  method: 'POST',
  headers: {
    Authorization: `Bearer ${getToken()}`
  },
  data: {
    target: artId, type: type, remark: remark
  }
})
// 搜索关键字，获取联想
export const getsuggestionAPI = (q) => requset({
  url: '/v1_0/suggestion',
  params: {
    q
  }
})
// 搜索，获取结果
export const searchReaultAPI = ({ page, per_page = 10, q }) => requset({
  url: '/v1_0/search',
  params: {
    page,
    per_page,
    q
  }
})
// 获取文章详情
export const getarticlesAPI = (article_id) => requset({
  url: `/v1_0/articles/${article_id}`
})
// 点击关注
export const followAPI = (target) => requset({
  url: '/v1_0/user/followings',
  method: 'POST',
  headers: {
    Authorization: `Bearer ${getToken()}`
  },
  data: {
    target
  }
})

// 点击取消关注
export const delfollowAPI = (target) => requset({
  url: `/v1_0/user/followings/${target}`,
  method: 'DELETE'
})
// 点赞文章
export const collectedAPI = (target) => requset({
  url: '/v1_0/article/likings',
  method: 'POST',
  data: {
    target
  }
})
// 取消点赞
export const delcollectedAPI = (target) => requset({
  url: `/v1_0/article/likings/${target}`,
  method: 'DELETE'
})
// 获取评论
export const getCommentsAPI = ({ type, source, offset = null, limit = 10 }) => requset({
  url: '/v1_0/comments',
  params: {
    type, source, offset, limit
  }
})
// 点赞评论
export const likeCommentAPI = (target) => requset({
  url: '/v1_0/comment/likings',
  method: 'POST',
  data: {
    target
  }
})
// 取消点赞评论
export const disLikeCommentAPI = (target) => requset({
  url: `/v1_0/comment/likings/${target}`,
  method: 'DELETE'
})

// 对文章评论
export const myCommentAPI = ({ target, content }) => requset({
  url: '/v1_0/comments',
  method: 'POST',
  data: {
    target,
    content
  }
})

// 获取用户自己信息
export const getUserMessageAPI = () => requset({
  url: '/v1_0/user'
})

// 获取用户个人信息
export const getoneUserMessageAPI = () => requset({
  url: '/v1_0/user/profile'
})
// 编辑用户个人信息
export const changeUserMessageAPI = ({ name, gender = '0', birthday, real_name = 'ze', intro = '美女' }) => requset({
  url: '/v1_0/user/profile',
  method: 'PATCH',
  data: { name, gender, birthday, real_name, intro }
})
// 编辑用户个人信息照片
export const changeUserPhotoMessageAPI = (formObj) => requset({
  url: '/v1_0/user/photo',
  method: 'PATCH',
  data: formObj
})
